package com.googlecode.nacl_optimizer.elf.headers;

import com.googlecode.nacl_optimizer.elf.types.Elf32Half;

public enum Machine {
    EM_NONE( new Elf32Half(0), "No machine"),
    EM_M32(  new Elf32Half(1), "AT&T WE 32100"),
    EM_SPARC(new Elf32Half(2), "SPARC"),
    EM_386 ( new Elf32Half(3), "Intel 386"),
    EM_68K ( new Elf32Half(4), "Motorola 68000"),
    EM_88K ( new Elf32Half(5), "Motorola 88000"),
    EM_860 ( new Elf32Half(7), "Intel 80860"),
    EM_MIPS( new Elf32Half(8), "MIPS RS3000 Big-Endian");

    private String text;
    private int v;
    
    private Machine(Elf32Half v, String text) {
        this.v=v.getInteger();
        this.text=text;
    }

    public static Machine getMachine(Elf32Half half) {
        for(Machine type: Machine.values()) {
            if(half.getInteger().equals(type.v)) {
                return type;
            }
        }
        throw new IllegalArgumentException();
    }

    @Override
    public String toString() {
        return this.text;
    }
}
